package com.hpu.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.hpu.entity.Order;
import com.hpu.util.DBhelp;
import com.hpu.util.RowMapper;

public class OrderDao {

	private DBhelp<Order> dbTable = new DBhelp<Order>();
	
	
	public List<Order> findAllOrders(){
		String sql = "select id,create_time,people_num,status,table_num,user_id,menu_id from t_order where status = ?";
		return dbTable.executeQueryForList(sql, new TableRowMapper(), false);
	}
	public List<Order> findAllPassOrders(){
		String sql = "select id,create_time,people_num,status,table_num,user_id,menu_id from t_order where status = ?";
		return dbTable.executeQueryForList(sql, new TableRowMapper(), true);
	}
	
	
	private class TableRowMapper implements RowMapper<Order>{
		public Order mapperRow(ResultSet rs) throws SQLException {
			Order order = new Order();
			order.setCreate_time(rs.getString("create_time"));
			order.setId(rs.getInt("id"));
			order.setMenu_id(rs.getString("menu_id"));
			order.setPeople_num(rs.getInt("people_num"));
			order.setStatus(rs.getBoolean("status"));
			order.setTable_num(rs.getInt("table_num"));
			order.setUser_id(rs.getString("user_id"));
			return order;
		}
		
		
		
		
	}
}
